package TCP_test2;

import java.io.*;
import java.net.Socket;
//文件
public class Client {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1",8888);
        //上传文件 字节流
        BufferedInputStream br = new BufferedInputStream(new FileInputStream("文件名"));
        BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream());
        byte[] bytes = new byte[1024];
        int len;
        while ((len = br.read(bytes)) != -1) {
            bos.write(bytes, 0, len);
        }
        //接收服务器的会写数据
        BufferedReader br2 = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String str2 = br2.readLine();
        System.out.println(str2);
        //关闭资源
        socket.close();
    }
}
